package com.ice.day726.thread;

import lombok.extern.slf4j.Slf4j;

/**
 * @Author ice2020x
 * @Date 2022-08-02 16:21
 * @Description: 打断线程
 */
@Slf4j
public class ThreadTest11 {
    public static void main(String[] args) {


        Thread t = new Thread(()->{
           while(true){
               boolean interrupted = Thread.currentThread().isInterrupted();
               if(interrupted){
                   log.debug("被打断了...");
                   break;
               }
           }
        });
        t.start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.debug("interrupt");
        t.interrupt();

    }
}
